﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using System.Data.Linq;

namespace HQC
{
   
    public partial class HqcDataContext
    {







        public IEnumerable<Interfaces.ISupplier> GetHQCSuppliers(DateTime lastSyncDate)
        {
            var sql = @"SELECT cast(LTrim(RTRim(SupplierID)) as int) as ID_Record, SupplierName, s.UpdatedDate UpdatedDate
                        FROM [REPDB].[dbo].[V_SUPPLIER] s
                            left join [REPDB].[dbo].[V_SupplierCode] sc
                            on s.[SupplierInternalKey] = sc.[SupplierInternalKey]
                        where 1=1 
                        and SupplierID is not null
                        and s.UpdatedDate >='{0}'
                        and  SupplierID >=5000
						and SupplierID < 100000
                        order by SupplierID";

            sql = String.Format(sql,lastSyncDate.ToString("yyyyMMdd"));
            
            return this.db.ExecuteQuery<HQCSupplier>(sql);
        }

        public IEnumerable<Interfaces.ILocation> GetHQCSites(DateTime lastSyncDate)
        {
            var sql = @" SELECT cast(StoreID as int) ID_Record,StoreName LocationName ,UpdatedDate
                      FROM [REPDB].[dbo].[V_Store] s
                      left join [dbo].[V_StoreCode] sc
                      on s.[StoreInternalKey] = sc.[StoreInternalKey]
                      where 1=1 and StoreID > 0
                        and UpdatedDate >= '{0}'
                        and StoreIsActive = 1
                      Order by StoreID";

            sql = String.Format(sql, lastSyncDate.ToString("yyyyMMdd"));            
            return this.db.ExecuteQuery<HQCSite>(sql);
        }


        public IEnumerable<Interfaces.IItem> GetHQCItems(DateTime lastSyncDate)
        {
            var sql = @" SELECT 
                          cast(ltrim(rtrim(MainItemId)) as bigint)   ID_RECORD
                          ,FullName ItemName
                          ,UpdatedDate
      
                      FROM [REPDB].[dbo].[V_ItemInfo]
                      where 1=1 AND IsFuel = 0 
                      and UpdatedDate >= '{0}'
                     --order by [MainItemId] desc
                      ";

            sql = String.Format(sql, lastSyncDate.ToString("yyyyMMdd"));
            return this.db.ExecuteQuery<HQCItem>(sql);
        }

        
    }
}